
from selenium.webdriver.common.by import By
from pages.base_page import BasePage


class ModifyCluePage(BasePage):
    url = "/crm/index.php?m=leads"
    result_locator = (By.XPATH, '/html/body/div[5]/div[2]')
    error_locator =(By.XPATH,"/html/body/div/form/fieldset/div[1]")
    amend_locator = (By.LINK_TEXT, '修改')  # 修改
    contacts_name_locator = (By.ID, 'contacts_name')  # 联系人姓名
    mobile_locator = (By.ID, 'mobile')  # 手机
    nextstep_time_locator = (By.ID, 'nextstep_time')  # 下次联系时间
    date_ok_locator = (By.CSS_SELECTOR,'#dpOkInput')    # 日期控件上的ok键
    nextstep_locator = (By.ID, 'nextstep')  # 下次联系内容
    description_locator = (By.ID, 'description')  # 备注
    save_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary')  # 保存
    tips_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')

    def __init__(self, driver):
        """
        重写父类的构造方法，获取到点击【修改】后进入的修改线索的资源路径，重新赋值给url
        """
        super().__init__(driver)
        super().open()
        amend_element = self.find_element(self.amend_locator)
        self.url = amend_element.get_attribute("href")

    def input_contacts_name(self, contacts_name):
        """
        修改联系人姓名
        """
        contacts_element = self.find_element(self.contacts_name_locator)
        contacts_element.clear()
        contacts_element.send_keys(contacts_name)

    def input_mobile(self, mobile):
        """
        修改手机
        """
        mobile_element = self.find_element(self.mobile_locator)
        mobile_element.clear()
        mobile_element.send_keys(mobile)

    def input_nextstep_time(self, nextstep_time):
        """
        修改下次联系时间
        """
        nextstep_time_element = self.find_element(self.nextstep_time_locator)
        nextstep_time_element.clear()
        nextstep_time_element.send_keys(nextstep_time)

    def click_date_ok(self):
        """
        点击日期控件上的ok键
        """
        self.find_element(self.date_ok_locator).click()

    def input_nextstep(self, nextstep):
        """
        修改下次联系内容
        """
        nextstep_element = self.find_element(self.nextstep_locator)
        nextstep_element.clear()
        nextstep_element.send_keys(nextstep)

    def input_descript(self, description):
        """
        修改备注
        """
        description_element = self.find_element(self.description_locator)
        description_element.clear()
        description_element.send_keys(description)

    def click_save(self):
        """
        点击保存
        """
        self.find_element(self.save_locator).click()

#返回增删改查后的提示信息
    def get_result_tips(self):
        return self.find_element(self.result_locator).text

#返回弹窗文本信息
    def get_alert_text(self):
        return self.driver.switch_to.alert.text

#返回报错弹窗文本信息
    def get_error_text(self):
        return self.find_element(self.error_locator).text

